<?php

namespace App\Http\Middleware;

use Closure;
use App\Models\Shop;
use Illuminate\Support\Facades\Auth;

class ShopCheck
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //检查路由
        if(!Auth::id()){
            return redirect()->back();
        }
        if($request->sid){
            $request->id = $request->sid;
        }
        $shop = Shop::where('user_id',Auth::id())->find($request->id);
        if(!$shop){
            return redirect()->back();
        }
        return $next($request);
    }
}
